﻿#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int findSubstringInWraproundString(string s) 
{
	int n = s.size();
	// 1. 利⽤ dp 求出每个位置结尾的最⻓连续⼦数组的⻓度
	vector<int> dp(n, 1);
	for (int i = 1; i < n; i++)
	{
		if (s[i] - 1 == s[i - 1] || (s[i - 1] == 'z' && s[i] == 'a'))
		{
			dp[i] = dp[i - 1] + 1;
		}
	}
		

	// 2. 计算每⼀个字符结尾的最⻓连续⼦数组的⻓度
	int hash[26] = { 0 };
	for (int i = 0; i < n; i++)
	{
		hash[s[i] - 'a'] = max(hash[s[i] - 'a'], dp[i]);
	}
	// 3. 将结果累加起来
	int sum = 0;
	for (auto x : hash)
	{
		sum += x;
	}

	return sum;
}
int main()
{
	string s = "abcde";
	cout << findSubstringInWraproundString(s) << endl;

	return 0;
}